package com.example.tossednfound;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

/**
 * Test the DB 
 */

public class SQLiteExample extends Activity implements OnClickListener {
	Button sign_in_button, sqlView;
	EditText sqlPassword, sqlEmail;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);
		sign_in_button = (Button) findViewById(R.id.sign_in_button);
		sqlEmail = (EditText) findViewById(R.id.email);
		sqlPassword = (EditText) findViewById(R.id.password);

		sqlView = (Button) findViewById(R.id.register_button);
		sqlView.setOnClickListener((android.view.View.OnClickListener) this); // this
																				// troubles
																				// me
	}

	@Override
	public void onClick(DialogInterface dialog, int which) {
		switch (which) {

		case R.id.sign_in_button:
			boolean didItWork = true;
			try {
				String email = sqlEmail.getText().toString();
				String password = sqlPassword.getText().toString();

				DatabaseHandler loginAttempt = new DatabaseHandler(
						SQLiteExample.this);
				loginAttempt.openReadable();
				boolean result = loginAttempt.checkLogin(email, password);
				loginAttempt.close();
				System.out.println(result);
			} catch (Exception e) {
				didItWork = false;
			} finally {
				if (didItWork) {
					Dialog d = new Dialog(this);
					d.setTitle("Heck Yea");
					TextView tv = new TextView(this);
					tv.setText("Sucess");
					d.setContentView(tv);
					d.show();
				}
			}
			break;
		case R.id.register_button:
			Intent newUserActivity = new Intent(
					"android.intent.action.NEWUSERACTIVITY");
			startActivity(newUserActivity);
			break;
		}

	}

}
